package sphere.view;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import sphere.controller.SphereController;

public class SphereWindow extends Frame{

	private Panel panel;
	private static final String radiusString = new String ("Radius = ");
	private static final String volumeString = new String ("Volume = ");
	private static final String surfaceString = new String ("Surface area = ");
	private TextField radiusText, volumeText, surfaceText;
	
	protected class PrivListener extends WindowAdapter {
		public void windowClosing (WindowEvent e ){
			System.exit (0) ;
		}
	}
	
	public SphereWindow(String titre){
		super(titre);
		PrivListener monListener= new PrivListener() ;
		this.addWindowListener(monListener) ;
		this.setLayout(new FlowLayout());
		this.panel = new Panel();
		this.panel.setLayout(new GridLayout(3,2,10,10));
		Label radiusLabel = new Label(radiusString);
		this.panel.add(radiusLabel);
		this.radiusText = new TextField();
		this.radiusText.setBackground(Color.pink);
		SphereController unListener = new SphereController(this);
		this.radiusText.addTextListener(unListener);
		this.panel.add(this.radiusText);
		Label volumeLabel = new Label(volumeString);
		this.panel.add(volumeLabel);
		this.volumeText = new TextField();
		this.volumeText.setEnabled(false);
		this.panel.add(this.volumeText);
		Label surfaceLabel = new Label(surfaceString);
		this.panel.add(surfaceLabel);
		this.surfaceText = new TextField();
		this.surfaceText.setEnabled(false);
		this.panel.add(this.surfaceText);
		this.add(panel);
		this.pack();
		this.setResizable(false);
		this.setVisible(true);
	}
	
	public TextField getSurfaceTextField(){
		return this.surfaceText;
	}
	public void setSurfaceTextField(String txt){
		this.surfaceText.setText(txt);
	}
	public TextField getVolumeTextField(){
		return this.volumeText;
	}
	public void setVolumeTextField(String txt){
		this.volumeText.setText(txt);
	}
}
